﻿#ifndef DURON_HTTPREQUESTER_H
#define DURON_HTTPREQUESTER_H

#include "HttpClientImp.h"

namespace toolkit {

	class HttpRequester : public HttpClientImp
	{
	public:
		typedef std::shared_ptr<HttpRequester> Ptr;
		typedef std::function<void(const SockException &ex, const string &status, const HttpHeader &header, const string &strRecvBody)> HttpRequesterResult;
		HttpRequester();
		virtual ~HttpRequester();
		void setOnResult(const HttpRequesterResult &onResult);
		void startRequester(const string &url, const HttpRequesterResult &onResult, float timeOutSecond = 10);
		void clear() override;
	private:
		ssize_t onResponseHeader(const string &status, const HttpHeader &headers) override;
		void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize)  override;
		void onResponseCompleted() override;
		void onDisconnect(const SockException &ex) override;
	private:
		string _strRecvBody;
		HttpRequesterResult _onResult;
	};

}//namespace toolkit

#endif /* DURON_HTTPREQUESTER_H */
